home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.4 / AdaptingToFonts / Example1.c next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  45.4 KB  |  1,232 lines

  1. /* :Programming/DevCon/Gadgets.C
  2.  
  3. History:
  4. 1.000 May 14, 1990  Jim2 - Stripped down from RTStock/Player.c
  5.  
  6. Description:
  7.       An example of sizing gadgets at run time.
  8.  *
  9.  *      Copyright (c) 1990 by MKSoft Development, James Barkley, Jr
  10.  *
  11.  ************************************************************************
  12.  *                                    *
  13.  * Permission is hereby granted to distribute this program's source    *
  14.  * executable, and documentation for non-commercial purposes, so long    *
  15.  * as the copyright notices are not removed from the sources,         *
  16.  * executable or documentation.  This program may not be distributed    *
  17.  * for a profit without the express written consent of the author James    *
  18.  * Barkley, Jr.                                      *
  19.  *                                    *
  20.  * This program is not in the public domain.                *
  21.  *                                    *
  22.  * Fred Fish is expressly granted permission to distribute this     *
  23.  * program's source and executable as part of the "Fred Fish freely     *
  24.  * redistributable Amiga software library."                *
  25.  *                                    *
  26.  * Permission is expressly granted for this program and it's source to     *
  27.  * be distributed as part of the Amicus Amiga software disks, and the    *
  28.  * First Amiga User Group's Hot Mix disks.                *
  29.  *                                    *
  30.  ************************************************************************
  31.  
  32.    ************************************************************************
  33.    *                                                                      *
  34.    *                            DISCLAIMER                                *
  35.    *                                                                      *
  36.    *   THIS SOFTWARE IS PROVIDED "AS IS".                                 *
  37.    *   NO REPRESENTATIONS OR WARRANTIES ARE MADE WITH RESPECT TO THE      *
  38.    *   ACCURACY, RELIABILITY, PERFORMANCE, CURRENTNESS, OR OPERATION      *
  39.    *   OF THIS SOFTWARE, AND ALL USE IS AT YOUR OWN RISK.                 *
  40.    *   NEITHER COMMODORE NOR THE AUTHORS ASSUME ANY RESPONSIBILITY OR     *
  41.    *   LIABILITY WHATSOEVER WITH RESPECT TO YOUR USE OF THIS SOFTWARE.    *
  42.    *                                                                      *
  43.    ************************************************************************
  44.  
  45.                                     */
  46. #include <math.h>
  47. #include <exec/types.h>
  48. #include <exec/memory.h>
  49. #include <string.h>
  50. #include "renderinfo.h"
  51.  
  52. #include <proto/exec.h>
  53. #include <proto/intuition.h>
  54. #include <proto/graphics.h>
  55.  
  56. struct RenderInfo *PenColors;
  57.  
  58. struct TextAttr Default_Font;
  59.  
  60. struct TextFont *Default_Text;
  61.  
  62.  
  63. UWORD Default_Font_Height;
  64.  
  65. struct Screen WBScrData;
  66.  
  67. #define STATI extern
  68. #define EXTERN extern
  69.  
  70. #define TEXTPEN0 1
  71.  
  72. #define XSKIP 12
  73. #define YSKIP  8
  74. #define X_ARROWS 25
  75. #define Y_ARROWS 14
  76. #define X_ARROW  15
  77. #define Y_ARROW  Y_ARROWS
  78.  
  79. #define ITICK_INTIAL_SKIP   3
  80. #define ITICK_REPEAT_SKIP   0
  81. #define ITICK_REPEAT_OFFSET (ITICK_INTIAL_SKIP - ITICK_REPEAT_SKIP)
  82.  
  83. #define UDATA_IS_FUNCTION 0
  84. #define UP_ARROW_FCN      1
  85. #define DOWN_ARROW_FCN      2
  86.  
  87. #define STOCK_NAME_DISPLAY_SIZE 6
  88.  
  89. #define MAXPOTLONG 0x0FFFFL
  90. #define ALMOST_MAXPOT (MAXPOTLONG -1)
  91.  
  92. #define PLAYER_PTR(X)  ((struct Player *) ((X)-> IDCMPWindow-> UserData))
  93. #define ACT_REQ_PTR(X) (PLAYER_PTR(X)-> Active_Req)
  94.  
  95. #define STR_INFO(X) ((struct StringInfo)((X)-> SpecialInfo))
  96.  
  97. #define HIT_GAD(X) ((struct Gadget *) (X-> IAddress))
  98.  
  99. typedef VOID (*GadgFun) (struct IntuiMessage *);
  100.  
  101. struct My_Gad
  102.    {
  103.    struct Gadget    Gad;
  104.    GadgFun        Fun;
  105.    struct IntuiText    *Select, *Deselect;
  106.    LONG            LineHeight;
  107.    };
  108.  
  109. struct Local_Name
  110.    {
  111.    struct Node    LN_Node;
  112.    UBYTE    Name [4];
  113.    };
  114.  
  115. struct Stock_List
  116.    {
  117.    struct MinList    List_Of;
  118.    struct Local_Name    *Top_Line;
  119.    LONG            List_Length, Top_Line_Num;
  120.    };
  121.  
  122. struct Player
  123.    {
  124.    LONG            Continue, ITick_Cnt;
  125.    struct Window     *Window;
  126.    struct Gadget    *Stock, *Price, *Share, *Day;
  127.    struct My_Gad    *ITick_Select;
  128.    struct Stock_List    Stocks;
  129.    struct Requester     Req_List[4], *Active_Req;
  130.    } ;
  131.  
  132. static UBYTE STOCK[]        = "Stock";
  133. static UBYTE SELL[]        = "Sell";
  134. static UBYTE BUY[]        = "Buy";
  135. static UBYTE SHARES[]        = "Shares";
  136. static UBYTE AT_MARKET[]    = "At Market";
  137. static UBYTE AT[]        = "Price";
  138. static UBYTE IMMEDIATE[]    = "Immediate";
  139. static UBYTE OPTION[]        = "Option";
  140. static UBYTE LAST_TRADE[]    = "Last Trade";
  141. static UBYTE ACCT_BAL[]        = "Acct Bal";
  142. static UBYTE COST[]        = "Cost";
  143. static UBYTE REVENUE[]        = "Revenue";
  144. static UBYTE NO_MARGIN[]    = "No Margin";
  145. static UBYTE MARGINED[]        = "Margined";
  146. static UBYTE EXECUTE[]        = "Execute";
  147. static UBYTE QUIT[]        = "Quit";
  148. static UBYTE GRAPH[]        = "Graph";
  149. static UBYTE PRICE[]        = "Price";
  150. static UBYTE DAYS[]        = "Days";
  151.  
  152. static struct IntuiText ITSell        = {1, 0, JAM1, 0, 0, &Default_Font, SELL, NULL};
  153. static struct IntuiText ITBuy        = {1, 0, JAM1, 0, 0, &Default_Font, BUY, NULL};
  154. static struct IntuiText ITAt_Market    = {1, 0, JAM1, 0, 0, &Default_Font, AT_MARKET, NULL};
  155. static struct IntuiText ITAt        = {1, 0, JAM1, 0, 0, &Default_Font, AT, NULL};
  156. static struct IntuiText ITImmediate    = {1, 0, JAM1, 0, 0, &Default_Font, IMMEDIATE, NULL};
  157. static struct IntuiText ITOption    = {1, 0, JAM1, 0, 0, &Default_Font, OPTION, NULL};
  158. static struct IntuiText ITCost        = {1, 0, JAM1, 0, 0, &Default_Font, COST, &ITBuy};
  159. static struct IntuiText ITRevenue    = {1, 0, JAM1, 0, 0, &Default_Font, REVENUE, &ITSell};
  160. static struct IntuiText ITNo_Margin    = {1, 0, JAM1, 0, 0, &Default_Font, NO_MARGIN, NULL};
  161. static struct IntuiText ITMargined    = {1, 0, JAM1, 0, 0, &Default_Font, MARGINED, NULL};
  162. static struct IntuiText ITExecute    = {1, 0, JAM1, 0, 0, &Default_Font, EXECUTE, NULL};
  163. static struct IntuiText ITQuit        = {1, 0, JAM1, 0, 0, &Default_Font, QUIT, NULL};
  164. static struct IntuiText ITGraph        = {1, 0, JAM1, 0, 0, &Default_Font, GRAPH, NULL};
  165.  
  166. static struct IntuiText ITBlank        = {1, 0, JAM1, 0, 0, &Default_Font, NULL, NULL};
  167.  
  168. static struct IntuiText ITStock        = {1, 0, JAM1, 0, 0, &Default_Font, STOCK, NULL};
  169. static struct IntuiText ITShares    = {1, 0, JAM1, 0, 0, &Default_Font, SHARES, &ITStock};
  170. static struct IntuiText ITLast_Trade    = {1, 0, JAM1, 0, 0, &Default_Font, LAST_TRADE, &ITShares};
  171. static struct IntuiText ITAcct_Bal    = {1, 0, JAM1, 0, 0, &Default_Font, ACCT_BAL, &ITLast_Trade};
  172.  
  173. static struct IntuiText IT_Values [] =
  174.     {{1, 0, JAM1, 0, 0, &Default_Font, NULL, NULL},                /*  0 */
  175.      {1, 0, JAM1, 0, 0, &Default_Font, NULL, &(IT_Values [0])},        /*  1 */
  176.      {1, 0, JAM1, 0, 0, &Default_Font, NULL, &(IT_Values [1])},        /*  2 */
  177.      {1, 0, JAM1, 0, 0, &Default_Font, NULL, &(IT_Values [2])}};        /*  3 */
  178.  
  179. static USHORT Up_Arrow [] =
  180.    {4, 9,
  181.     4, 0,
  182.     3, 1,
  183.     5, 1,
  184.     7, 2,
  185.     1, 2,
  186.     0, 3,
  187.     8, 3};
  188. static USHORT Down_Arrow [] =
  189.    {4, 0,
  190.     4, 9,
  191.     3, 8,
  192.     5, 8,
  193.     7, 7,
  194.     1, 7,
  195.     0, 6,
  196.     8, 6};
  197. static USHORT Box_Arrow_Upper [] =
  198.    {23,  0,
  199.      0,  0,
  200.      0, 13,
  201.      1, 12,
  202.      1,  1};
  203. static USHORT Box_Arrow_Lower [] =
  204.    { 1, 13,
  205.     24, 13,
  206.     24,  0,
  207.     23,  1,
  208.     23, 12};
  209. static USHORT Box_List [] =
  210.    {2,  0, 0,  0, 0,  1, 1,  2, 1,  1,    /*   0 Day Requester Top */
  211.     1,  1, 1,  1, 1,  0, 2,  1, 2,  1,    /*  10 Day Requester Bottom */
  212.     2,  0, 0,  0, 0,  1, 1,  2, 1,  1,    /*  20 Price Requester Top */
  213.     1,  1, 1,  1, 1,  0, 2,  1, 2,  1,    /*  30 Price Requester Bottom */
  214.     2,  0, 0,  0, 0,  1, 1,  2, 1,  1,    /*  40 Share Requester Top */
  215.     1,  1, 1,  1, 1,  0, 2,  1, 2,  1,    /*  50 Share Requester Bottom */
  216.     2,  0, 0,  0, 0,  1, 1,  2, 1,  1,    /*  60 Stock Requester Top */
  217.     1,  1, 1,  1, 1,  0, 2,  1, 2,  1,    /*  70 Stock Requester Bottom */
  218.     2,  0, 0,  0, 0,  1, 1,  2, 1,  1,    /*  80 Day IntuiText Top */
  219.     1,  1, 1,  1, 1,  0, 2,  1, 2,  1,    /*  90 Day IntuiText Bottom */
  220.     2,  0, 0,  0, 0,  1, 1,  2, 1,  1,    /* 100 Price IntuiText Top */
  221.     1,  1, 1,  1, 1,  0, 2,  1, 2,  1,    /* 110 Price IntuiText Bottom */
  222.     2,  0, 0,  0, 0,  1, 1,  2, 1,  1,    /* 120 Share IntuiText Top */
  223.     1,  1, 1,  1, 1,  0, 2,  1, 2,  1,    /* 130 Share IntuiText Bottom */
  224.     2,  0, 0,  0, 0, 13, 1, 12, 1,  1,    /* 140 Day Arrow Top */
  225.     1, 13, 1, 13, 1,  0, 2,  1, 2, 12,    /* 150 Day Arrow Bottom */
  226.     2,  0, 0,  0, 0, 13, 1, 12, 1,  1,    /* 160 Price Arrow Top */
  227.     1, 13, 1, 13, 1,  0, 2,  1, 2, 12,    /* 170 Price Arrow Bottom */
  228.     2,  0, 0,  0, 0, 13, 1, 12, 1,  1,    /* 180 Share Arrow Top */
  229.     1, 13, 1, 13, 1,  0, 2,  1, 2, 12,    /* 190 Share Arrow Bottom */
  230.     2,  0, 0,  0, 0, 13, 1, 12, 1,  1,    /* 200 Price Arrow Odd Ball Top */
  231.     1, 13, 1, 13, 1,  0, 2,  1, 2, 12,    /* 210 Price Arrow Odd Ball Bottom */
  232.     2,  0, 0,  0, 0, 13, 1, 12, 1,  1,    /* 220 Stock Arrow Top */
  233.     1, 13, 1, 13, 1,  0, 2,  1, 2, 12,     /* 230 Stock Arrow Bottom */
  234.     2,  0, 0,  0, 0, 13, 1, 12, 1,  1,    /* 240 Stock Listing Top */
  235.     1, 13, 1, 13, 1,  0, 2,  1, 2, 12,    /* 250 Stock Listing Bottom */
  236.     2,  0, 0,  0, 0,  1, 1,  2, 1,  1,    /* 260 Gadget Box Top */
  237.     1,  1, 1,  1, 1,  0, 2,  1, 2,  1,    /* 270 Gadget Box Bottom */
  238.     2,  1, 2,  0, 3,  1, 3,  1, 1,  1,    /* 280 Inner-gadget box Top */
  239.     1,  1, 1,  1, 1,  2, 2,  1, 3,  1};    /* 290 Inner-gadget box Bottom */
  240.  
  241. static struct Border Border_LA_Up = {0, 0, 1, 0, JAM1, 5, Box_Arrow_Lower, NULL};
  242. static struct Border Border_Arrow_Up = {0, 0, 1, 0, JAM1, 5, Box_Arrow_Upper, &Border_LA_Up};
  243. static struct Border Border_LA_Down = {0, 0, 1, 0, JAM1, 5, Box_Arrow_Lower, NULL};
  244. static struct Border Border_Arrow_Down = {0, 0, 1, 0, JAM1, 5, Box_Arrow_Upper, &Border_LA_Down};
  245.  
  246. static struct Border Border_UA_Double_Up = {4, 2, 1, 0, JAM1, 8, Up_Arrow, &Border_Arrow_Up};
  247. static struct Border Border_Arrow_Double_Up = {12, 2, 1, 0, JAM1, 8, Down_Arrow, &Border_UA_Double_Up};
  248. static struct Border Border_Up_Arrow_Up = {7, 2, 1, 0, JAM1, 8, Up_Arrow, &Border_Arrow_Up};
  249. static struct Border Border_Down_Arrow_Up = {7, 2, 1, 0, JAM1, 8, Down_Arrow, &Border_Arrow_Down};
  250.  
  251. static struct Border Border_UA_Double_Down = {4, 2, 1, 0, JAM1, 8, Up_Arrow, &Border_Arrow_Down};
  252. static struct Border Border_Arrow_Double_Down = {12, 2, 1, 0, JAM1, 8, Down_Arrow, &Border_UA_Double_Down};
  253. static struct Border Border_Up_Arrow_Down = {7, 2, 1, 0, JAM1, 8, Up_Arrow, &Border_Arrow_Down};
  254. static struct Border Border_Down_Arrow_Down = {7, 2, 1, 0, JAM1, 8, Down_Arrow, &Border_Arrow_Down};
  255.  
  256. /* High 27 = Up single        High 29 = Up Double
  257.    High 28 = Down Single    Shad 29 = Down Double            */
  258.  
  259. static struct Border Highlight_Borders [];
  260.  
  261. static struct Border Shadow_Borders [] =
  262.    {{-4, -2, 1, 0, JAM1, 5, &(Box_List[270]), NULL},            /*  0 Used */
  263.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[260]), &(Highlight_Borders[13])},/*  1 Used */
  264.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[260]), &(Shadow_Borders[7])},    /*  2 Used */
  265.     {-2, -1, 1, 0, JAM1, 5, &(Box_List[250]), NULL},            /*  3 Used */
  266.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[260]), &(Shadow_Borders[2])},    /*  4 Used */
  267.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[260]), &(Shadow_Borders[4])},    /*  5 Used */
  268.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[220]), NULL,},            /*  6 Used */
  269.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[280]), &(Highlight_Borders[17])},/*  7 Used */
  270.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[230]), NULL},            /*  8 Used */
  271.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[150]), NULL},            /*  9 Used */
  272.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[180]), NULL,},            /* 10 Used */
  273.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[140]), NULL},            /* 11 Used */
  274.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[190]), NULL},            /* 12 Used */
  275.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[200]), NULL,},            /* 13 Used */
  276.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[170]), NULL},            /* 14 Used */
  277.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[160]), NULL},            /* 15 Used */
  278.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[210]), NULL},            /* 16 Used */
  279.     { 0,  0, 1, 0, JAM1, 5, Box_List, NULL},                /* 17 Used */
  280.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[120]), NULL},            /* 18 Used */
  281.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[20]), NULL},            /* 19 Used */
  282.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[100]), NULL},            /* 20 Used */
  283.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[40]), NULL},            /* 21 Used */
  284.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[130]), NULL},            /* 22 Used */
  285.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[80]), NULL},            /* 23 Used */
  286.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[60]), NULL},            /* 24 Used */
  287.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[110]), NULL},            /* 25 Used */
  288.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[90]), NULL},            /* 26 Used */
  289.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[260]), NULL},            /* 27 Used */
  290.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[270]), NULL},            /* 28 Used */
  291.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[280]), &(Highlight_Borders[30])},/* 29 Used */
  292.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[290]), &(Highlight_Borders[27])},/* 30 Used */
  293.     {-2, -1, 1, 0, JAM1, 5, &(Box_List[240]), NULL}};            /* 31 Used */
  294.  
  295. static struct Border Highlight_Borders [] =
  296.    {{ 0,  0, 1, 0, JAM1, 5, &(Box_List[100]), &Shadow_Borders[25]},    /*  0 Used */
  297.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[120]), &Shadow_Borders[22]},    /*  1 Used */
  298.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[90]), &(Shadow_Borders[23])},    /*  2 Used */
  299.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[110]), &(Shadow_Borders[20])},    /*  3 Used */
  300.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[130]), &(Shadow_Borders[18])},    /*  4 Used */
  301.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[200]), &(Shadow_Borders[16])},    /*  5 Used */
  302.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[210]), &(Shadow_Borders[13])},    /*  6 Used */
  303.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[180]), &(Shadow_Borders[12])},    /*  7 Used */
  304.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[190]), &(Shadow_Borders[10])},    /*  8 Used */
  305.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[220]), &(Shadow_Borders[8])},    /*  9 Used */
  306.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[230]), &(Shadow_Borders[6])},    /* 10 Used */
  307.     {-2, -1, 1, 0, JAM1, 5, &(Box_List[240]), &(Shadow_Borders[3])},    /* 11 Used */
  308.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[260]), &(Shadow_Borders[0])},    /* 12 Used */
  309.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[270]), &(Highlight_Borders[27])},/* 13 Used */
  310.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[270]), &(Shadow_Borders[5])},    /* 14 Used */
  311.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[270]), &(Highlight_Borders[14])},/* 15 Used */
  312.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[270]), &(Highlight_Borders[15])},/* 16 Used */
  313.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[290]), &(Highlight_Borders[12])},/* 17 Used */
  314.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[140]), &(Shadow_Borders[9])},    /* 18 Used */
  315.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[150]), &(Shadow_Borders[11])},    /* 19 Used */
  316.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[160]), &(Shadow_Borders[14])},    /* 20 Used */
  317.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[170]), &(Shadow_Borders[15])},    /* 21 Used */
  318.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[10]), &(Shadow_Borders[17])},    /* 22 Used */
  319.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[30]), &(Shadow_Borders[19])},    /* 23 Used */
  320.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[50]), &(Shadow_Borders[21])},    /* 24 Used */
  321.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[70]), &(Shadow_Borders[24])},    /* 25 Used */
  322.     { 0,  0, 1, 0, JAM1, 5, &(Box_List[80]), &Shadow_Borders[26]},    /* 26 Used */
  323.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[260]), &(Shadow_Borders[28])},    /* 27 Used */
  324.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[270]), &(Shadow_Borders[27])},    /* 28 Used */
  325.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[280]), &(Shadow_Borders[30])},    /* 29 Used */
  326.     {-4, -2, 1, 0, JAM1, 5, &(Box_List[290]), &(Highlight_Borders[28])},/* 30 Used */
  327.     {-2, -1, 1, 0, JAM1, 5, &(Box_List[250]), &(Shadow_Borders[31])}};    /* 31 Used */
  328.  
  329. static UBYTE Stock_String[4], Price_String[8];
  330.  
  331. static UBYTE Share_String[8]  = "0",
  332.          Option_String[4] = "0",
  333.          Price_String[8]  = "0.00";
  334.  
  335. static struct StringInfo Stock_SInfo = {Stock_String, NULL, 0, 4, 0, 0, 0, 0, 0, 3, NULL, 0};
  336. static struct StringInfo Share_SInfo = {Share_String, NULL, 0, 8, 0, 0, 0, 0, 0, 0, NULL, 0};
  337. static struct StringInfo Price_SInfo = {Price_String, NULL, 0, 8, 0, 0, 0, 0, 0, 0, NULL, 0};
  338. static struct StringInfo Option_SInfo = {Option_String, NULL, 0, 4, 0, 0, 0, 0, 0, 0, NULL, 0};
  339.  
  340. static struct Image Back_Option_Execute, Back_Option_Quit, Back_Option_Graph;
  341.  
  342. static struct Image Image_List [] =
  343.    {{0, 63, 5, 29, 0, NULL, 0x0000, 0x0000, NULL}};    /*  0 */
  344.  
  345. static struct PropInfo PI_List [] =
  346.    {{AUTOKNOB | FREEVERT, -1, 0, -1, MAXBODY}};    /*  0 */
  347.  
  348. static struct My_Gad Rate; /* forward reference */
  349.  
  350. static struct My_Gad Fill_Back =
  351.    {NULL, 0, 0, 0, 0, GADGHNONE | GADGIMAGE, 0, BOOLGADGET, (APTR) &Back_Option_Execute,
  352.     NULL, &ITAcct_Bal, 0, NULL, 0, NULL, NULL} ;
  353.  
  354. static struct My_Gad Option_Execute =
  355.    {NULL, 0, 0, 0, 0, GADGHIMAGE, RELVERIFY, BOOLGADGET, (APTR) &(Highlight_Borders[29]),
  356.     (APTR) &(Shadow_Borders[29]), &ITExecute, 0, NULL, 0, NULL, NULL};
  357.  
  358. static struct My_Gad Option_Quit =
  359.    {NULL, 0, 0, 0, 0, GADGHIMAGE, RELVERIFY, BOOLGADGET, (APTR) &(Highlight_Borders[29]),
  360.     (APTR) &(Shadow_Borders[29]), &ITQuit, 0, NULL, 0, NULL, NULL};
  361.  
  362. static struct My_Gad Option_Graph =
  363.    {NULL, 0, 0, 0, 0, GADGHIMAGE, RELVERIFY, BOOLGADGET, (APTR) &(Highlight_Borders[29]),
  364.     (APTR) &(Shadow_Borders[29]), &ITGraph, 0, NULL, 0, NULL, NULL};
  365.  
  366. static struct My_Gad Stock_Name =
  367.    {NULL, 0, 0, 0, 0, GADGHCOMP, RELVERIFY | STRINGCENTER, STRGADGET, (APTR) &Highlight_Borders[16],
  368.     NULL, &(IT_Values[2]), 0, (APTR) &Stock_SInfo, 0, NULL, NULL};
  369.  
  370. static struct My_Gad Share_Num =
  371.    {NULL, 0, 0, 0, 0, GADGHCOMP, RELVERIFY | STRINGRIGHT | LONGINT, STRGADGET,
  372.     (APTR) &(Shadow_Borders[7]), NULL, NULL, 0,
  373.     (APTR) &Share_SInfo, 0, (APTR) &Rate, NULL};
  374.  
  375. static struct My_Gad Price_Num =
  376.    {NULL, 0, 0, 0, 0, GADGHCOMP, RELVERIFY | STRINGRIGHT, STRGADGET,
  377.     (APTR) &(Shadow_Borders[7]), NULL, NULL, 0,
  378.     (APTR) &Price_SInfo, 0, (APTR) &Share_Num, NULL};
  379.  
  380. static struct My_Gad Option_Num =
  381.    {NULL, 0, 0, 0, 0, GADGHCOMP, RELVERIFY | STRINGRIGHT | LONGINT, STRGADGET,
  382.     (APTR) &(Shadow_Borders[7]), NULL, NULL, 0,
  383.     (APTR) &Option_SInfo, 0, NULL, NULL};
  384.  
  385. static struct My_Gad Buy_Sell =
  386.    {NULL, 0, 0, 0, 0, GADGHNONE | SELECTED, GADGIMMEDIATE | TOGGLESELECT,
  387.     BOOLGADGET, (APTR) &(Shadow_Borders [1]), NULL, &ITCost, 0, NULL, 0, NULL, NULL, &ITCost, &ITRevenue};
  388.  
  389. static struct My_Gad Acct_Type =
  390.    {NULL, 0, 0, 0, 0, GADGHNONE | SELECTED, GADGIMMEDIATE | TOGGLESELECT,
  391.     BOOLGADGET, (APTR) &(Highlight_Borders[27]), NULL, &ITNo_Margin, 0, NULL, 0, NULL, NULL, &ITNo_Margin, &ITMargined};
  392.  
  393. static struct My_Gad Rate =
  394.    {NULL, 0, 0, 0, 0, GADGHNONE | SELECTED, GADGIMMEDIATE | TOGGLESELECT,
  395.     BOOLGADGET, (APTR) &(Highlight_Borders[27]), NULL, &ITAt_Market, 0, NULL, 0, NULL, NULL, &ITAt_Market, &ITAt};
  396.  
  397. static struct My_Gad When =
  398.    {NULL, 0, 0, 0, 0, GADGHNONE | SELECTED, GADGIMMEDIATE | TOGGLESELECT,
  399.     BOOLGADGET, (APTR) &(Highlight_Borders[27]), NULL, &ITImmediate, 0, NULL, 0, NULL, NULL, &ITImmediate, &ITOption};
  400.  
  401. /* ClearGadget
  402.  
  403. History:
  404. 1.000 Apr 23, 1990  Jim2 - Written based on My_RemoveGadget
  405.  
  406. Description:
  407.       Removes a gadget from the window and clears the hit box of the
  408.       gadget.  The color and drawing mode are assume to be set already.
  409. Globals:  NONE
  410. Modules:  NONE
  411. Parameters:
  412.       Here    Pointer to the window where the gadget is displayed.
  413.       This    Pointer to the gadget to be removed and cleared.
  414. Locals:  NONE
  415.                                     */
  416. STATI LONG ClearGadget (struct Window * Here, struct Gadget * This)
  417.  
  418.    {
  419.    RectFill (Here-> RPort, This-> LeftEdge, This-> TopEdge, This-> LeftEdge
  420.     + This-> Width - 1, This-> TopEdge + This-> Height - 1);
  421.    return (RemoveGadget (Here, This));
  422.    } /* ClearGadget */
  423.  
  424. #define GAD_BORDER(x) ((struct Border *) (x-> GadgetRender))
  425.  
  426. /* My_RemoveGadget
  427.  
  428. History:
  429. 1.100 Apr 23, 1990  Jim2
  430.       Commented, clear the hit box and the border assuming that the border
  431.       is symmetric about the gadget.
  432.  
  433. Description:
  434.       Removes a gadget from the window and attempt to clear the hit box
  435.       area as well as the border.  The color is assumed to be set already.
  436. Globals:  NONE
  437. Modules:  NONE
  438. Parameters:
  439.       Here    Pointer to the window where the gadget is displayed.
  440.       This    Pointer to the gadget to be removed and cleared.
  441. Locals:  NONE
  442.                                     */
  443. STATI LONG My_RemoveGadget (struct Window * Here, struct Gadget * This)
  444.  
  445.    {
  446.    SetDrMd (Here-> RPort, JAM1);
  447.    if (This-> GadgetRender == NULL)
  448.       return (ClearGadget (Here, This));
  449.    if ((GAD_BORDER(This)-> LeftEdge >= 0) || (GAD_BORDER(This)-> TopEdge >= 0))
  450.       return (ClearGadget (Here, This));
  451.       RectFill (Here-> RPort, This-> LeftEdge + GAD_BORDER (This)-> LeftEdge,
  452.     This-> TopEdge + GAD_BORDER (This)-> TopEdge, This-> LeftEdge + This->
  453.     Width - (GAD_BORDER (This)-> LeftEdge + 1), This-> TopEdge + This->
  454.     Height - (GAD_BORDER (This)-> TopEdge + 1));
  455.    return (RemoveGadget (Here, This));
  456.    } /* My_RemoveGadget */
  457.  
  458. /* Change_IText
  459.  
  460. History:
  461. 1.100 Jan 16, 1990  Jim2
  462.       Keep the gadget at the same position in the list.
  463. 1.000 Jan 12, 1990  Jim2 - Written.
  464.  
  465. Description:
  466.       Changes the IntuiText displayed on a gadget.
  467. Globals:  NONE
  468. Modules:  NONE
  469. Parameters:
  470.       Here    Pointer to the window upon which the gadget is displayed.
  471.       This    Pointer to the gadget.
  472.       Swapped    Pointer to the new IntuiText.
  473. Locals:
  474.       Pos    Position of the gadget in the gadget list.
  475.                                     */
  476. STATI VOID Change_IText (struct Window * Here, struct Gadget * This, struct IntuiText * Swapped)
  477.  
  478.    {
  479.    register LONG Pos;
  480.  
  481.    SetAPen (Here-> RPort, Swapped-> BackPen);
  482.    if ((Pos = ClearGadget (Here, This)) != -1)
  483.       {
  484.       This-> GadgetText = Swapped;
  485.       AddGadget (Here, This, Pos);
  486.       RefreshGList (This, Here, NULL, 1);
  487.       }
  488.    } /* Change_IText */
  489.  
  490. /* Alternate_Single
  491.  
  492. History:
  493. 2.000 Apr 20, 1990  Jim2
  494.       Augumented the gadget structure to include the Select and NoSelect
  495.       IntuiTexts
  496. 1.000 Jan 11, 1990  Jim2 - Written.
  497.  
  498. Description
  499.       Changes the IntuiText of a gadget based on the select flag of the
  500.       gadget.
  501. Globals:  NONE
  502. Modules:  NONE
  503. Parameters:
  504.       This_Win    Pointer to the window where the gadget is displayed.
  505.       This    Pointer to the augmented gadget.
  506. Locals:  NONE
  507.                                     */
  508. STATI VOID Alternate_Single (struct Window *This_Win, struct My_Gad *This)
  509.  
  510.    {
  511.    if (((This-> Gad. Flags) & SELECTED) != 0)
  512.       Change_IText (This_Win, (struct Gadget *) This, This-> Select);
  513.    else
  514.       Change_IText (This_Win, (struct Gadget *) This, This-> Deselect);
  515.    } /* Alternate_Single */
  516.  
  517.  
  518.  
  519. /* Hit_Buy_Sell
  520.  
  521. History:
  522. 2.100 Apr 27, 1990  Jim2
  523.       To prevent autorepeating, clear the ITick_Select value in the player
  524.       structure.
  525. 2.000 Apr 20, 1990  Jim2
  526.       Changed to support new Alternate Single.  Reduced the use of Module
  527.       level variables.
  528. 1.110 Feb 13, 1990  Jim2 - Clear out the lower intuitext.
  529. 1.100 Jan 16, 1990  Jim2
  530.       What the heck, lets link the IntuiText and make a new border type
  531.       and only use a single gadget here.
  532.       Added parameter as a beginning to remove references to Modules level
  533.       variables.  This will allow for the possiblity of multiple player.
  534. 1.000 Jan 11, 1990  Jim2 - Written.
  535.  
  536. Description:
  537.       Swaps the IntuiTexts for the Buy_Sell gadget based on the selected
  538.       state of the Buy_Sell gadget.
  539. Globals:  NONE
  540. Modules:
  541.       Referenced:  ITBuy, ITSell, ITCost, ITRevenue.
  542. Parameters:
  543.       Mess    Pointer to the message recieved when this gadget was
  544.         hit.  All information can be accessed from here.
  545. Locals:
  546.       This    Pointer to the extended gadget structure that was hit.
  547.                                     */
  548. STATI VOID Hit_Buy_Sell (struct IntuiMessage * Mess)
  549.  
  550.    {
  551.    register struct Gadget * This;
  552.  
  553.    This = (struct Gadget *) Mess-> IAddress;
  554.    SetAPen (Mess-> IDCMPWindow-> RPort, This-> GadgetText-> BackPen);
  555.    RectFill (Mess-> IDCMPWindow-> RPort, This-> GadgetText-> LeftEdge + This->
  556.     LeftEdge, This-> GadgetText-> TopEdge + This-> TopEdge, This-> GadgetText->
  557.     LeftEdge + This-> Width + This-> LeftEdge, This-> GadgetText-> TopEdge
  558.     + Default_Font_Height + This-> TopEdge);
  559.    Alternate_Single (Mess-> IDCMPWindow, (struct My_Gad *) This);
  560.    ((struct Player *) Mess-> IDCMPWindow-> UserData)-> ITick_Select = NULL;
  561.    } /* Hit_Buy_Sell */
  562.  
  563. /* Get_Last_Price
  564.  
  565. History:
  566. 1.000 Apr 18, 1990  Jim2 - Primative version written.
  567.  
  568. Description:
  569.       Checks to see if the stock name passed is still a viable stock.
  570.       If so the monitoring port for this task is added to the monitor
  571.       list and the last trade value is added.  If the Rate gadget is
  572.       set to immediate the price is changed to last price.
  573. Globals:  NONE
  574. Modules:
  575. Parameters:
  576.       Stock    Pointer to the string of the stock name.
  577.       Price    Pointer to the Intuitext structure where the last price is
  578.         displayed.
  579. Locals:  NONE
  580.                                     */
  581. STATI LONG Get_Last_Price (UBYTE Stock[], struct IntuiText * Price, struct Window *Win)
  582.  
  583.    {
  584.       {
  585.       if (Price-> IText[2] == '0')
  586.      Price-> IText[2] = '5';
  587.       else
  588.      {
  589.      Price-> IText[2] = '0';
  590.      if (Price-> IText[0] == '9')
  591.         Price-> IText[0] = '1';
  592.      else
  593.         (Price-> IText[0])++;
  594.      }
  595.       SetAPen (Win-> RPort, Price-> BackPen);
  596.       RectFill (Win-> RPort, Stock_Name. Gad. LeftEdge, Stock_Name. Gad. TopEdge + Price-> TopEdge, Stock_Name. Gad. LeftEdge + Stock_Name. Gad. Width - 1, Stock_Name. Gad. TopEdge + Price->
  597. TopEdge + Win-> RPort-> TxHeight);
  598.       Price-> LeftEdge = Stock_Name. Gad. Width - IntuiTextLength (Price);
  599.       return (TRUE);
  600.       }
  601.    } /* Get_Last_Price */
  602.  
  603. /* Release_Stock_String
  604.  
  605. History:
  606. 1.001 Apr 10, 1990  Jim2 - Renamed.
  607. 1.000 Mar  6, 1990  Jim2 - Wrote stub.
  608.  
  609. Description:
  610.       Check the stock name for validity lock main lock main semaphore and
  611.       do find.  Send monitoring message to stock task.  Recalculate cost
  612.       and account balance (this should include reseting shares number if
  613.       acct_Bal < 0).
  614. Globals:  NONE
  615. Modules:  NONE
  616. Parameters:
  617.       Mess    Pointer to the message recieved when this gadget was hit.
  618.         All information can be accessed from here.
  619. Locals:  NONE
  620.                                     */
  621. STATI VOID Release_Stock_String (struct IntuiMessage * Mess)
  622.    {
  623.    if (Get_Last_Price (((struct StringInfo *) ((struct Gadget *) Mess-> IAddress)-> SpecialInfo)-> Buffer, ((struct Gadget *) Mess-> IAddress)-> GadgetText, Mess-> IDCMPWindow))
  624.       RefreshGList ((struct Gadget *) Mess-> IAddress, Mess-> IDCMPWindow, NULL, 1);
  625.    } /* Release_Stock_String */
  626.  
  627. /* Hit_Acct_Type
  628.  
  629. History:
  630. 2.100 Apr 27, 1990  Jim2
  631.       To prevent autorepeating, clear the ITick_Select filed of the player
  632.       structure.
  633. 2.000 Apr 20, 1990  Jim2
  634.       Removed use of module level variables and support a revised
  635.       Alternate_Single.
  636. 1.100 Jan 16, 1990  Jim2
  637.       Added parameter as a beginning to remove references to Modules level
  638.       variables.  This will allow for the possiblity of multiple player.
  639. 1.000 Jan 11, 1990  Jim2 - Written.
  640.  
  641. Description:
  642.       Changes the IntuiText message in the Acct_Type gadget.
  643. Globals:  NONE
  644. Modules:  NONE
  645. Parameters:
  646.       Mess    Pointer to the message recieved when this gadget was
  647.         hit.  All information can be accessed from here.
  648. Locals:  NONE
  649.                                     */
  650. STATI VOID Hit_Alternate (struct IntuiMessage * Mess)
  651.  
  652.    {
  653.    Alternate_Single (Mess-> IDCMPWindow, (struct My_Gad *) Mess-> IAddress);
  654.    ((struct Player *) Mess-> IDCMPWindow-> UserData)-> ITick_Select = NULL;
  655.    } /* Hit_Acct_Type */
  656.  
  657. /* Hit_Option_Execute
  658.  
  659. History:
  660. 1.200 Jan 16, 1990  Jim2
  661.       Added parameter to make this routine match the other Hit_?? routines.
  662. 1.100 Jan 15, 1990  Jim2
  663.       Saw some code that actually used an Alert.
  664.       Use backslahes, not foward slashes.
  665. 1.000 Jan 11, 1990  Jim2 - Wrote stub that does a DisplayAlert.
  666.  
  667. Description:
  668.       Takes the action for the execute option.
  669. Globals:  NONE
  670. Modules:  NONE
  671. Parameters:
  672.       Mess    Pointer to the message recieved when this gadget was
  673.         hit.  All information can be accessed from here.
  674. Locals:  NONE
  675.                                     */
  676. STATI VOID Hit_Option_Execute (struct IntuiMessage * Mess)
  677.  
  678.    {
  679.    DisplayAlert (RECOVERY_ALERT, "\000\360\020 Hit Execute button\00", 44L);
  680.    } /* Hit_Option_Execute */
  681.  
  682. /* Hit_Option_Quit
  683.  
  684. History:
  685. 1.200 Jan 16, 1990  Jim2
  686.       Added parameter to make this routine match the other Hit_?? routines.
  687. 1.000 Jan 11, 1990  Jim2 - Wrote stub that does a DisplayAlert.
  688.  
  689. Description:
  690.       Takes the action for the quit option.
  691. Globals:  NONE
  692. Modules:  NONE
  693. Parameters:
  694.       Mess    Pointer to the message recieved when this gadget was
  695.         hit.  All information can be accessed from here.
  696. Locals:  NONE
  697.                                     */
  698. STATI VOID Hit_Option_Quit (struct IntuiMessage * Mess)
  699.  
  700.    {
  701.    ((struct Player *) (Mess-> IDCMPWindow-> UserData))-> Continue = FALSE;
  702.    } /* Hit_Option_Quit */
  703.  
  704. /* Hit_Option_Graph
  705.  
  706. History:
  707. 1.200 Jan 16, 1990  Jim2
  708.       Added parameter to make this routine match the other Hit_?? routines.
  709. 1.000 Jan 11, 1990  Jim2 - Wrote stub that does a DisplayAlert.
  710.  
  711. Description:
  712.       Takes the action for the graph option.
  713. Globals:  NONE
  714. Modules:  NONE
  715. Parameters:
  716.       Mess    Pointer to the message recieved when this gadget was
  717.         hit.  All information can be accessed from here.
  718. Locals:  NONE
  719.                                     */
  720. STATI VOID Hit_Option_Graph (struct IntuiMessage * Mess)
  721.  
  722.    {
  723.    DisplayAlert (RECOVERY_ALERT, "\x00\xF0\x0A This function is not yet implemented\x00", 18L);
  724.    } /* Hit_Option_Graph */
  725.  
  726. /* Center
  727.  
  728. History:
  729. 2.000 Apr 16, 1990  Jim2 - Only need the TxHeight, not the whole RastPort.
  730. 1.000 Jan 11, 1990  Jim2 - Written.
  731.  
  732. Description:
  733.       Centers an IntuiText string in a box of size X, Y.
  734. Globals:  NONE
  735. Modules:  NONE
  736. Parameters:
  737.       Text    Pointer to the IntuiText to be centered.
  738.       TxHeight    Height of the font of the text.
  739.       X, Y    Box size.
  740. Locals:  NONE
  741.                                     */
  742. STATI VOID Center (struct IntuiText *Text, LONG TxHeight, LONG X, LONG Y)
  743.  
  744.    {
  745.    Text-> TopEdge = (Y - TxHeight)/ 2;
  746.    Text-> LeftEdge = (X - IntuiTextLength (Text)) / 2;
  747.    }
  748.  
  749. /* Initialize_Borders
  750.  
  751. History:
  752. 2.000 Apr 11, 1990  Jim2
  753.       The vector arrays for the boxes have been moved in the module
  754.       variable, Box_List.  The fixed values are initialized by the
  755.       system.  Since half of the indicies for the double box are the
  756.       indicies for a single box they are not repeated.  Instead, an
  757.       addition border structure will be used.  This will allow for
  758.       the two tone string gadget borders.
  759. 1.000 Jan 11, 1990  Jim2 - Written.
  760.  
  761. Description:
  762.       Sets up the vector arrays so they make an X by Y box.
  763. Globals:  NONE
  764. Modules:
  765.       Altered:    Box_List
  766. Parameters:
  767.       X_Size, Y_Size  the outer dimensions of the box.
  768. Locals:  NONE
  769.                                     */
  770. STATI VOID Initialize_Borders (LONG X_Size, LONG Y_Size)
  771.    {
  772.    Y_Size += 3;
  773.    Box_List[271] = Box_List[273] = Box_List[265] = Y_Size--;
  774.    Box_List[267] = Box_List[279] = Box_List[291] = Box_List[297] = Box_List[299]
  775.     =  Box_List[283] = Y_Size--;
  776.    Box_List[285] = Y_Size;
  777.  
  778.    X_Size += 7;
  779.    Box_List[272] = Box_List[274] = X_Size--;
  780.    Box_List[276] = Box_List[278] = Box_List[260] = X_Size--;
  781.    Box_List[290] = Box_List[292] = X_Size--;
  782.    Box_List[294] = Box_List[296] = Box_List[288] = X_Size;
  783.    } /* Initialize_Borders */
  784.  
  785. /* Size_Boxes
  786.  
  787. History:
  788. 2.100 Apr 23, 1990  Jim2
  789.       Don't include the borders in the size of the boxes.
  790. 2.000 Apr 17, 1990  Jim2
  791.       The boxes should be sized before the window is opened to determine
  792.       the size the window needs to me.  Therefore add the parameters that
  793.       pass the width of the top and left border and return the size of
  794.       the window less the bottom and right border.  Also we need the
  795.       height of the font being used.
  796. 1.000 Jan 11, 1990  Jim2 - Written.
  797.  
  798. Description:
  799.       Sizes the boxes and intializes the border structures so the boxes
  800.       box the largest string based on the users defualt font type.
  801.  
  802. Globals:
  803.       Referenced:  Default_Font_Height.
  804. Modules:
  805.       Altered:       ITSell, ITBuy, ITAt_Market, ITAt, ITImmediate, ITOption,
  806.            ITCost, ITRevenue, ITNo_Margin, ITMargined, ITExecute,
  807.            ITQuit, ITGraph.
  808.       Referenced:  STOCK, SHARES, LAST_TRADE, ACCT_BAL.
  809. Parameters:
  810.       BorderTop        Height of the top border of the window where the
  811.             gadgets are to be rendered.
  812.       BorderLeft    Width of the left border of the window where the
  813.             gadgets are to be rendered.
  814.       Height        Height required of the window to allow the gadgets
  815.             to be rendered.  Included is the height of the top,
  816.             but not the bottom border.
  817.       Width        Width required of the window to allow the gadgets
  818.             to be rendered.  Included is the width of the left,
  819.             but not the right border.
  820. Locals:
  821.       I            Loop Control;
  822.       X, Y        Size of the box.
  823.       X_Pos, Y_Pos    Position of the Gadget in the window.
  824.       Text_Offset    Additional offset needed to center text.
  825.                                     */
  826. STATI VOID Size_Boxes (LONG BorderTop, BYTE BorderLeft, SHORT * Height, SHORT
  827.     * Width)
  828.  
  829.    {
  830.    register LONG         I, X, Y, X_Pos, Y_Pos, Text_Offset;
  831.  
  832. #define V_POS_GAD(G) (G). Gad. TopEdge = Y_Pos; Y_Pos += Y + YSKIP
  833. #define V_POS_TEXT_GAD(G) (G). Gad. TopEdge = Y_Pos + Text_Offset; Y_Pos += Y + YSKIP
  834.  
  835.  
  836.    Y = Default_Font_Height;
  837.    Y += max (Y / 10, 2);
  838.    X = max (0, IntuiTextLength (&ITSell));
  839.    X = max (X, IntuiTextLength (&ITBuy));
  840.    X = max (X, IntuiTextLength (&ITAt_Market));
  841.    X = max (X, IntuiTextLength (&ITAt));
  842.    X = max (X, IntuiTextLength (&ITImmediate));
  843.    X = max (X, IntuiTextLength (&ITOption));
  844.    X = max (X, IntuiTextLength (&ITCost));
  845.    X = max (X, IntuiTextLength (&ITRevenue));
  846.    X = max (X, IntuiTextLength (&ITNo_Margin));
  847.    X = max (X, IntuiTextLength (&ITMargined));
  848.    X = max (X, IntuiTextLength (&ITGraph));
  849.    X = max (X, IntuiTextLength (&ITExecute));
  850.    X = max (X, IntuiTextLength (&ITQuit));
  851.    X = max (X, IntuiTextLength (&ITStock));
  852.    X = max (X, IntuiTextLength (&ITShares));
  853.    X = max (X, IntuiTextLength (&ITLast_Trade));
  854.    X = max (X, IntuiTextLength (&ITAcct_Bal));
  855.    X += max (X / 10, 2);
  856.    Initialize_Borders (X, Y);
  857.    Center (&ITSell, Default_Font_Height, X, Y);
  858.    Center (&ITBuy, Default_Font_Height, X, Y);
  859.    Center (&ITAt_Market, Default_Font_Height, X, Y);
  860.    Center (&ITAt, Default_Font_Height, X, Y);
  861.    Center (&ITImmediate, Default_Font_Height, X, Y);
  862.    Center (&ITOption, Default_Font_Height, X, Y);
  863.    Center (&ITCost, Default_Font_Height, X, Y);
  864.    Center (&ITRevenue, Default_Font_Height, X, Y);
  865.    Center (&ITNo_Margin, Default_Font_Height, X, Y);
  866.    Center (&ITMargined, Default_Font_Height, X, Y);
  867.    Center (&ITExecute, Default_Font_Height, X, Y);
  868.    Center (&ITQuit, Default_Font_Height, X, Y);
  869.    Center (&ITGraph, Default_Font_Height, X, Y);
  870.    Center (&ITStock, Default_Font_Height, X, Y);
  871.    Center (&ITLast_Trade, Default_Font_Height, X, Y);
  872.    Center (&ITAcct_Bal, Default_Font_Height, X, Y);
  873.    Center (&ITShares, Default_Font_Height, X, Y);
  874.  
  875.    Buy_Sell. Gad. Width = Rate. Gad. Width = When. Gad. Width = Acct_Type.
  876.     Gad. Width = Option_Execute. Gad. Width = Back_Option_Execute. Width
  877.     = Option_Quit. Gad. Width = Back_Option_Quit. Width = Option_Graph.
  878.     Gad. Width = Back_Option_Graph. Width = X;
  879.  
  880.    Buy_Sell. Gad. Height = Rate. Gad. Height = When. Gad. Height = Acct_Type.
  881.     Gad. Height = Option_Execute. Gad. Height = Back_Option_Execute. Height
  882.     = Option_Quit. Gad. Height = Back_Option_Quit. Height = Option_Graph.
  883.     Gad. Height = Back_Option_Graph. Height = Y;
  884.  
  885.    Stock_Name. Gad. Height = Share_Num. Gad. Height = Price_Num. Gad. Height
  886.     = Option_Num. Gad. Height = Default_Font_Height;
  887.  
  888.    Text_Offset = (Y - Default_Font_Height) / 2;
  889.    Shadow_Borders[0]. TopEdge = Shadow_Borders[7]. TopEdge = Highlight_Borders[12]. TopEdge
  890.     = Highlight_Borders[17]. TopEdge -= Text_Offset;
  891.  
  892.    X_Pos = BorderLeft + XSKIP;
  893.    Y_Pos = BorderTop + YSKIP;
  894.  
  895.    Buy_Sell. Gad. LeftEdge = Rate. Gad. LeftEdge = When. Gad. LeftEdge = X_Pos;
  896.  
  897.    ITStock. LeftEdge += X_Pos;
  898.    ITStock. TopEdge += Y_Pos;
  899.    Y_Pos += YSKIP + Y;
  900.    V_POS_GAD (Buy_Sell);
  901.    ITShares. LeftEdge += X_Pos;
  902.    ITShares. TopEdge += Y_Pos;
  903.    Y_Pos += YSKIP + Y;
  904.    V_POS_GAD (Rate);
  905.    V_POS_GAD (When);
  906.    ITLast_Trade. LeftEdge += X_Pos;
  907.    ITLast_Trade. TopEdge += Y_Pos;
  908.    Y_Pos += YSKIP + Y;
  909.    ITAcct_Bal. LeftEdge += X_Pos;
  910.    ITAcct_Bal. TopEdge += Y_Pos;
  911.    Y_Pos += YSKIP + Y;
  912.    Shadow_Borders[1]. TopEdge = Highlight_Borders[13]. TopEdge += Y_Pos - Buy_Sell. Gad. TopEdge;
  913.    ITRevenue. TopEdge = ITCost. TopEdge += (Highlight_Borders[13]. TopEdge + 2);
  914.    *Height = Y_Pos + YSKIP + Y;
  915.  
  916.    X_Pos += XSKIP + X;
  917.    Y_Pos = BorderTop + YSKIP;
  918.  
  919.    X_Pos += XSKIP + X_ARROWS;
  920.    Y_Pos = BorderTop + YSKIP;
  921.  
  922.    Stock_Name. Gad. LeftEdge = Acct_Type. Gad. LeftEdge = Share_Num. Gad. LeftEdge =
  923.     Price_Num. Gad. LeftEdge = Option_Num. Gad. LeftEdge = X_Pos;
  924.  
  925.    Stock_Name. Gad. Width = Share_Num. Gad. Width = Price_Num. Gad. Width =
  926.        Option_Num. Gad. Width = X;
  927.  
  928.    V_POS_TEXT_GAD (Stock_Name);
  929.    Stock_String[0] = '\0';
  930.    V_POS_GAD (Acct_Type);
  931.    V_POS_TEXT_GAD (Share_Num);
  932.    V_POS_TEXT_GAD (Price_Num);
  933.    V_POS_TEXT_GAD (Option_Num);
  934.    Shadow_Borders[5]. TopEdge = Highlight_Borders[16]. TopEdge += Y_Pos - Stock_Name. Gad. TopEdge;
  935.    Shadow_Borders[4]. TopEdge = Highlight_Borders[15]. TopEdge = Highlight_Borders[16]. TopEdge + Y + YSKIP;
  936.    Shadow_Borders[2]. TopEdge = Highlight_Borders[14]. TopEdge = Highlight_Borders[15]. TopEdge + Y + YSKIP;
  937.    I = IT_Values[2]. TopEdge = Shadow_Borders[5]. TopEdge + ITSell. TopEdge + 2;
  938.    IT_Values[1]. TopEdge = I += (Y + YSKIP);
  939.    IT_Values[0]. TopEdge = I + Y + YSKIP;
  940.  
  941.    X_Pos += XSKIP + XSKIP + X;
  942.    Y_Pos = BorderTop + YSKIP + (3 * Y) / 2;
  943.  
  944.    Option_Execute. Gad. LeftEdge = Back_Option_Execute. LeftEdge = Option_Quit.
  945.     Gad. LeftEdge = Back_Option_Quit. LeftEdge = Option_Graph. Gad. LeftEdge
  946.     = Back_Option_Graph. LeftEdge = X_Pos;
  947.  
  948.    Option_Execute. Gad. TopEdge = Back_Option_Execute. TopEdge = Y_Pos;
  949.    Option_Quit. Gad. TopEdge = Back_Option_Quit. TopEdge = Y_Pos += 2 * (Y
  950.     + YSKIP);
  951.    Option_Graph. Gad. TopEdge = Back_Option_Graph. TopEdge = Y_Pos += 2 * (Y
  952.     + YSKIP);
  953.  
  954.    Back_Option_Execute.TopEdge-=BorderTop;
  955.    Back_Option_Quit.TopEdge-=BorderTop;
  956.    Back_Option_Graph.TopEdge-=BorderTop;
  957.  
  958.    ITStock.TopEdge-=BorderTop;
  959.    ITShares.TopEdge-=BorderTop;
  960.    ITLast_Trade.TopEdge-=BorderTop;
  961.    ITAcct_Bal.TopEdge-=BorderTop;
  962.  
  963.    Back_Option_Execute.LeftEdge-=BorderLeft;
  964.    Back_Option_Quit.LeftEdge-=BorderLeft;
  965.    Back_Option_Graph.LeftEdge-=BorderLeft;
  966.  
  967.    ITStock.LeftEdge-=BorderLeft;
  968.    ITShares.LeftEdge-=BorderLeft;
  969.    ITLast_Trade.LeftEdge-=BorderLeft;
  970.    ITAcct_Bal.LeftEdge-=BorderLeft;
  971.  
  972.    Fill_Back.Gad.LeftEdge=BorderLeft;
  973.    Fill_Back.Gad.TopEdge=BorderTop;
  974.  
  975.    Back_Option_Execute. Depth = Back_Option_Execute. PlanePick = Back_Option_Quit.
  976.     Depth = Back_Option_Quit. PlanePick = Back_Option_Graph. Depth = Back_Option_Graph.
  977.     PlanePick = 0;
  978.  
  979.    Back_Option_Execute. NextImage = &Back_Option_Quit;
  980.    Back_Option_Quit. NextImage = &Back_Option_Graph;
  981.  
  982.    Back_Option_Execute. ImageData = Back_Option_Quit. ImageData = Back_Option_Graph.
  983.     ImageData = NULL;
  984.    Back_Option_Graph. NextImage = NULL;
  985.  
  986.    *Width = X_Pos + X + XSKIP;
  987.    } /* Size_Boxes*/
  988.  
  989. #define NORMAL_TEXT(X,Y)    (X). FrontPen = TEXTPEN0; (X). BackPen = 0
  990. #define REVERSE_TEXT(X,Y)   (X). FrontPen = 0; (X). BackPen = TEXTPEN0
  991.  
  992. /* Initial_Player_Window_Structures
  993.  
  994. History:
  995. 1.000 Jan 16, 1990  Jim2 - Written.
  996.  
  997. Description:
  998.       Sets up all of the defaults for the information which will be
  999.       constant regardless of the number of players.
  1000. Globals:
  1001.       Referenced:  PenColors
  1002. Modules:
  1003.       Altered:    Border_LS_Up, Border
  1004. Parameters:  NONE
  1005. Locals:
  1006.       I    Loop Control
  1007.                                     */
  1008.  
  1009. EXTERN VOID Initial_Player_Window_Structures (VOID)
  1010.  
  1011.    {
  1012.    register LONG I;
  1013.  
  1014.    Border_LA_Up. FrontPen = PenColors-> Shadow;
  1015.    Border_Arrow_Up. FrontPen = PenColors-> Highlight;
  1016.    Border_LA_Down. FrontPen = PenColors-> Highlight;
  1017.    Border_Arrow_Down. FrontPen = PenColors-> Shadow;
  1018.  
  1019.    Border_UA_Double_Up. FrontPen = TEXTPEN0;
  1020.    Border_Arrow_Double_Up. FrontPen = TEXTPEN0;
  1021.    Border_Up_Arrow_Up. FrontPen = TEXTPEN0;
  1022.    Border_Down_Arrow_Up. FrontPen = TEXTPEN0;
  1023.  
  1024.    Border_UA_Double_Down. FrontPen = TEXTPEN0;
  1025.    Border_Arrow_Double_Down. FrontPen = TEXTPEN0;
  1026.    Border_Up_Arrow_Down. FrontPen = TEXTPEN0;
  1027.    Border_Down_Arrow_Down. FrontPen = TEXTPEN0;
  1028.  
  1029.    for (I = 0; I <= sizeof (Shadow_Borders) / sizeof (struct Border);)
  1030.       Shadow_Borders[I++]. FrontPen = PenColors-> Shadow;
  1031.    for (I = 0; I <= sizeof (Highlight_Borders)/ sizeof (struct Border);)
  1032.       Highlight_Borders[I++]. FrontPen = PenColors-> Highlight;
  1033.  
  1034.    NORMAL_TEXT (ITSell, PenColors);
  1035.    NORMAL_TEXT (ITBuy, PenColors);
  1036.    NORMAL_TEXT (ITAt_Market, PenColors);
  1037.    NORMAL_TEXT (ITAt, PenColors);
  1038.    NORMAL_TEXT (ITImmediate, PenColors);
  1039.    NORMAL_TEXT (ITOption, PenColors);
  1040.    NORMAL_TEXT (ITCost, PenColors);
  1041.    NORMAL_TEXT (ITRevenue, PenColors);
  1042.    NORMAL_TEXT (ITNo_Margin, PenColors);
  1043.    NORMAL_TEXT (ITMargined, PenColors);
  1044.  
  1045.    REVERSE_TEXT (ITExecute, PenColors);
  1046.    REVERSE_TEXT (ITQuit, PenColors);
  1047.    REVERSE_TEXT (ITGraph, PenColors);
  1048.  
  1049.    NORMAL_TEXT (ITStock, PenColors);
  1050.    NORMAL_TEXT (ITShares, PenColors);
  1051.    NORMAL_TEXT (ITLast_Trade, PenColors);
  1052.    NORMAL_TEXT (ITAcct_Bal,PenColors);
  1053.  
  1054.    Back_Option_Execute. PlaneOnOff = TEXTPEN0;
  1055.    Back_Option_Quit. PlaneOnOff = TEXTPEN0;
  1056.    Back_Option_Graph. PlaneOnOff = TEXTPEN0;
  1057.  
  1058.    Buy_Sell. Fun = Hit_Buy_Sell;
  1059.    Acct_Type. Fun= Hit_Alternate;
  1060.    Rate. Fun = Hit_Alternate;
  1061.    When. Fun = Hit_Alternate;
  1062.  
  1063.    Option_Execute. Fun = Hit_Option_Execute;
  1064.    Option_Quit. Fun =  Hit_Option_Quit;
  1065.    Option_Graph. Fun = Hit_Option_Graph;
  1066.  
  1067.  
  1068.    Stock_Name. Fun = Release_Stock_String;
  1069.  
  1070.  
  1071.    } /* Initial_Player_Window_Structures */
  1072.  
  1073. /*  Run_Player
  1074.  
  1075. History:
  1076. 1.200 May  7, 1990  Jim2
  1077.       Intialize the new elements in the Player record.
  1078. 1.100 Apr 18, 1990  Jim2
  1079.       Handle extended gadget structures.  Size the window and position
  1080.       it at the bottom of the screen.  Display the Stock requester forcing
  1081.       the user to choose a stock at the start.  Don't forget to free the
  1082.       string for the cost.
  1083. 1.000 Jan 17, 1990  Jim2 - Written as a subroutine.
  1084.  
  1085. Description:
  1086.       This task handles the interactions for a single player of the
  1087.       stock market game.
  1088. Globals:  NONE
  1089. Modules:  NONE
  1090. Parameters:
  1091.       Player    Pointer to the information for this player.
  1092. Locals:
  1093.       Info1
  1094.       Temp
  1095.                                     */
  1096. EXTERN VOID Run_Player (struct Player * Player)
  1097.  
  1098.    {
  1099. #define WINDOW (Player-> Window)
  1100.  
  1101.    register struct IntuiMessage *Info1;
  1102.    register APTR        Temp;
  1103.  
  1104.    struct NewWindow nw = {0, 0, 640, 200, 0, 1, GADGETUP | GADGETDOWN| CLOSEWINDOW | NOCAREREFRESH | INTUITICKS,
  1105.     WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG,
  1106.     NULL, NULL, (UBYTE *) "Trial GUI by Jim2, MKSoft", NULL, NULL, 0, 0, -1, -1, WBENCHSCREEN};
  1107.  
  1108.    Player-> ITick_Select = NULL;
  1109.    Player-> ITick_Cnt = 0;
  1110.    NewList ((struct List *) &Player-> Stocks. List_Of);
  1111.  
  1112.    nw. DetailPen = PenColors-> TextPen;
  1113.    nw. BlockPen = PenColors-> BackPen;
  1114.    Size_Boxes (WBScrData. BarHeight + WBScrData. WBorTop, WBScrData. WBorLeft,
  1115.      &(nw. Height), &(nw. Width));
  1116.  
  1117.    nw. Height += WBScrData. WBorBottom;
  1118.    nw. Width += WBScrData. WBorRight;
  1119.    if ((nw. Height <= WBScrData. Height) && (nw. Width <=  WBScrData. Width))
  1120.       {
  1121.       nw. TopEdge = WBScrData. Height - nw. Height;
  1122.       WINDOW = OpenWindow (&nw);
  1123.       SetFont (WINDOW-> RPort, Default_Text);
  1124.       WINDOW-> UserData = (BYTE *) Player;
  1125.  
  1126.       SetAPen (WINDOW->RPort, PenColors->TextPen);
  1127.       SetBPen (WINDOW->RPort, PenColors->BackPen);
  1128.  
  1129.       Player-> Stock = (struct Gadget *) &Stock_Name;
  1130.       Player-> Price = (struct Gadget *) &Price_Num;
  1131.       Player-> Share = (struct Gadget *) &Share_Num;
  1132.       Player-> Day = (struct Gadget *) &Option_Num;
  1133.       AddGadget (WINDOW, (struct Gadget *) &Buy_Sell, -1);
  1134.       AddGadget (WINDOW, (struct Gadget *) &Acct_Type, -1);
  1135.       AddGadget (WINDOW, (struct Gadget *) &Rate, -1);
  1136.       AddGadget (WINDOW, (struct Gadget *) &When, -1);
  1137.       AddGadget (WINDOW, (struct Gadget *) &Option_Execute, -1);
  1138.       AddGadget (WINDOW, (struct Gadget *) &Option_Quit, -1);
  1139.       AddGadget (WINDOW, (struct Gadget *) &Option_Graph, -1);
  1140.       AddGadget (WINDOW, Player-> Stock, -1);
  1141.       AddGadget (WINDOW, Player-> Share, -1);
  1142.       AddGadget (WINDOW, Player-> Price, -1);
  1143.       AddGadget (WINDOW, Player-> Day, -1);
  1144.       AddGadget (WINDOW, (struct Gadget *) &Fill_Back, -1);
  1145.       RefreshGList (WINDOW-> FirstGadget, WINDOW, NULL, -1);
  1146.       Player-> Continue = TRUE;
  1147.       do
  1148.      {
  1149.      WaitPort (WINDOW-> UserPort);
  1150.      while ((Info1 = (struct IntuiMessage *) GetMsg (WINDOW-> UserPort)) != NULL)
  1151.         {
  1152.         if (Player-> Continue)
  1153.            switch (Info1-> Class)
  1154.           {
  1155.           case CLOSEWINDOW :
  1156.              Player-> Continue = FALSE;
  1157.              break;
  1158.           case GADGETDOWN  :
  1159.              {
  1160.              Player-> ITick_Select = (struct MyGad *) Info1-> IAddress;
  1161.              Player-> ITick_Cnt = 0;
  1162.              if (((struct My_Gad *) Info1-> IAddress)-> Fun != NULL)
  1163.             (((struct My_Gad *) Info1-> IAddress)-> Fun) (Info1);
  1164.              }
  1165.              break;
  1166.           case GADGETUP    :
  1167.              if (((struct My_Gad *) Info1-> IAddress)-> Fun != NULL)
  1168.             (((struct My_Gad *) Info1-> IAddress)-> Fun) (Info1);
  1169.              break;
  1170.           case INTUITICKS   :
  1171.              if (Player-> ITick_Cnt < ITICK_INTIAL_SKIP)
  1172.             (Player-> ITick_Cnt)++;
  1173.              else
  1174.             if (Player-> ITick_Select != NULL)
  1175.                if (((Player-> ITick_Select-> Gad. Flags) & SELECTED) != 0)
  1176.                 {
  1177.                     if (Player-> ITick_Select-> Fun)
  1178.                        {
  1179.                        Temp = Info1-> IAddress;
  1180.                        Info1-> IAddress = (APTR) Player-> ITick_Select;
  1181.                        Player-> ITick_Select-> Fun (Info1);
  1182.                        Info1-> IAddress = Temp;
  1183.                        }
  1184.                 }
  1185.                else
  1186.                   Player-> ITick_Select = NULL;
  1187.              break;
  1188.           }
  1189.         ReplyMsg ((struct Message *) Info1);
  1190.         }
  1191.      }
  1192.       while (Player-> Continue);
  1193.       CloseWindow (WINDOW);
  1194.       }
  1195.    }
  1196.  
  1197.  
  1198. main (VOID)
  1199.  
  1200. {
  1201. struct Player *Player;
  1202.  
  1203. IntuitionBase = (struct InuitionBase *) OpenLibrary ("intuition.library", 33L);
  1204. GfxBase = (struct GfxBase *) OpenLibrary ("graphics.library", 33L);
  1205. GetScreenData ((char *) &WBScrData, sizeof (struct Screen), WBENCHSCREEN, NULL);
  1206. Forbid ();
  1207. Default_Font. ta_Name = WBScrData. Font-> ta_Name;
  1208. Default_Font. ta_YSize = WBScrData. Font-> ta_YSize;
  1209. Default_Font. ta_Style = WBScrData. Font-> ta_Style;
  1210. Default_Font. ta_Flags = WBScrData. Font-> ta_Flags;
  1211. Default_Text = OpenFont (&Default_Font);
  1212. Permit ();
  1213. Default_Font_Height = Default_Text-> tf_YSize;
  1214. Player = (struct Player *) AllocMem (sizeof (struct Player), MEMF_CLEAR | MEMF_PUBLIC);
  1215. if (PenColors=Get_RenderInfo(&WBScrData))
  1216.    {
  1217.    IT_Values[2]. IText = AllocMem (4L, MEMF_CLEAR);
  1218.    strcpy (IT_Values[2]. IText, "1.00");
  1219.  
  1220.    Initial_Player_Window_Structures ();
  1221.  
  1222.    Run_Player (Player);
  1223.  
  1224.    CleanUp_RenderInfo(PenColors);
  1225.    }
  1226.  
  1227. FreeMem (Player, sizeof (struct Player));
  1228. CloseFont (Default_Text);
  1229. CloseLibrary ((struct Library *) GfxBase);
  1230. CloseLibrary ((struct Library *) IntuitionBase);
  1231. }
  1232.